﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HA.Data;
using System.Windows.Controls;
using HA.ModFlow.Controls.Windows.MapData;
namespace HA.ModFlow.Application
{
   public class CoverageViewModel:MDTVIViewModel
    {
       public CoverageViewModel(MDTVIViewModel parent,Coverage c)
           : base()
       {
           this._defaultCoverage = c;





           this._contextMenu = new System.Windows.Controls.ContextMenu();
           MenuItem mi = new MenuItem();
           mi.Header = "缩放到...";
           mi.Command = GISCommands.ExtentToCurrent;

           mi.CommandParameter = this._defaultCoverage.Key.ToString();

           this._contextMenu.Items.Add(mi);

           this._contextMenu.Items.Add(new Separator());

               
               
           mi = new MenuItem();
           mi.Header = "删除";
           mi.Command = DataCommands.RemoveCMCoverage;
           mi.CommandParameter = c;
           this._contextMenu.Items.Add(mi);


           // mi = new MenuItem();
           //mi.Header = "重命名";
           //this._contextMenu.Items.Add(mi);


           mi = new MenuItem();
           mi.Header = "复制";
           mi.Command = DataCommands.DuplicateCMCoverage;
           mi.CommandParameter = this._defaultCoverage;
           this._contextMenu.Items.Add(mi);

           Separator sep = new Separator();
           this._contextMenu.Items.Add(sep);

           mi = new MenuItem();
           mi.Header = "图层设置";
           mi.Command = DataCommands.CoverageSetup;
           mi.CommandParameter = this._defaultCoverage;
           this._contextMenu.Items.Add(mi);

           mi = new MenuItem();
           mi.Header = "属性表";
           mi.Command = DataCommands.CoverageAttributeTable;
           mi.CommandParameter = this._defaultCoverage;

           this._contextMenu.Items.Add(mi);



           //mi = new MenuItem();
           //mi.Header = "Build3DGrid";
           //mi.Command = DataCommands.CoverageMap3DGrid;
           //mi.CommandParameter = this._defaultCoverage;

           //this._contextMenu.Items.Add(mi);



           mi = new MenuItem();
           mi.Header = "构建多边形";
           mi.Command = DataCommands.BuildPolygon;
           mi.CommandParameter = this._defaultCoverage;

           this._contextMenu.Items.Add(mi);





           mi = new MenuItem();
           mi.Header = "映射到";
           //子项
           MenuItem menu;

           // menu = new MenuItem();
           //menu.Header = "TIN";
           //mi.Items.Add(menu);

           // menu = new MenuItem();
           //menu.Header = "2D Mesh";
           //mi.Items.Add(menu);

           //menu = new MenuItem();
           //menu.Header = "2D Scatter Points";
           //mi.Items.Add(menu);

           //Separator sep1 = new Separator();
           //mi.Items.Add(sep1);

           menu = new MenuItem();
           menu.Header = "MODFLOW模型";
           menu.Command = DataCommands.CoverageMapToModFlow;
           menu.CommandParameter = this._defaultCoverage;

           mi.Items.Add(menu);



           menu = new MenuItem();
           menu.Header = "MT3DMS模型";
           menu.Command = DataCommands.CoverageMapToMT3D;

           menu.CommandParameter = this._defaultCoverage;

           mi.Items.Add(menu);



           //menu = new MenuItem();
           //menu.Header = "FEMWATER";
           //mi.Items.Add(menu);

           //menu = new MenuItem();
           //menu.Header = "SEEP2D";
           //mi.Items.Add(menu);

           //menu = new MenuItem();
           //menu.Header = "ADH";
           //mi.Items.Add(menu);





           //子项结束

           sep = new Separator();
           this._contextMenu.Items.Add(sep);

           //MenuItem miProp = new MenuItem();

           //miProp.Header = "属性";

           //this._contextMenu.Items.Add(miProp);





           this._contextMenu.Items.Add(mi);


           this._imageSource = VMImageSource.Coverage;




           //订阅对应的时间
           this._defaultCoverage.NameChanged += new EventHandler(_defaultCoverage_NameChanged);




       }




       void _defaultCoverage_NameChanged(object sender, EventArgs e)
       {
           this.OnPropertyChanged("Desc");
       }


       public override System.Windows.Input.ICommand DoubleClickCommand
       {
           get
           {
               //return DataCommands.CoverageSetup;

               return new RelayCommand((m)=>this.EditCoverageSetup());

           }
       }


       public void EditCoverageSetup()
       {
           winCoverageSetup cs = new winCoverageSetup(this._defaultCoverage);
           cs.Owner = GisModule.mainWindow;
           if (cs.ShowDialog() == true)
           {
               _defaultCoverage.Setup = cs.PCCoverageSetup.Setup;
               _defaultCoverage.Name = cs.PCCoverageSetup.CoverageName;

           } 


       }


       Coverage _defaultCoverage;

       public Coverage DefaultCoverage
       {
           get { return _defaultCoverage; }
           set { _defaultCoverage = value; }
       }

       public override string Desc
       {
           get
           {
               return HAUtil.LanguageTranslater.ENToCN(this._defaultCoverage.Name);
           }
       }


       protected override void OnSelectedChanged()
       {
           if (this.IsSelected)
           {
             

               GisModule.DefaultModule.GisManager.InteractiveSystem.CurrentLayer = GisModule.DefaultModule.GisManager.LayerSystem.LayerCollection.GetLayer(this._defaultCoverage.Key.ToString());

               UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.ToolVM.CurrentTool = APPTOOLMODE.MAPDATA;

           }

       }


       protected override void OnCheckedChanged()
       {
           base.OnCheckedChanged();

          HAGISV2.Layer layer=   GisModule.DefaultModule.GisManager.LayerSystem.LayerCollection.GetLayer(this._defaultCoverage.Key.ToString());

           if (layer!=null)
	        {
               layer.Visible=this.IsChecked;
		 
	        }
       }

    }
}
